#-*- encoding: utf-8 -*-
#---------------------------------------------------------------------------------
# SConscript
# Copyright (c) 2024, Shanghai Real-Thread Electronic Technology Co., Ltd.
#---------------------------------------------------------------------------------
import os
from building import *
Import('RTT_ROOT')
Import('rtconfig')

#---------------------------------------------------------------------------------
# Package configuration
#---------------------------------------------------------------------------------
PKGNAME = 'hpm_lib'
DEPENDS = []

#---------------------------------------------------------------------------------
# Compile the configuration
#---------------------------------------------------------------------------------
CPPDEFINES=[]
SOURCES          = []
CPPPATH          = [os.path.join(GetCurrentDir(), 'debug_console'), 
					os.path.join(GetCurrentDir(), 'touch'),
	 				os.path.join(GetCurrentDir(), 'usb'), 
					os.path.join(GetCurrentDir(), 'dma_mgr')]
SOURCES         += Glob('debug_console/hpm_debug_console.c')
SOURCES         += Glob('dma_mgr/hpm_dma_mgr.c')

if GetDepend(['BSP_USING_TOUCH_GT9xx']):
	SOURCES     += Glob('touch/gt9xx/hpm_touch_gt9xx.c')
	SOURCES     += Glob('touch/gt9xx/hpm_gt9xx.c')
	CPPPATH     += ['touch/gt9xx']
	CPPDEFINES += ['CONFIG_TOUCH_GT9XX=1']

if GetDepend(['BSP_USING_TOUCH_FT5406']):
	SOURCES     += Glob('touch/ft5406/hpm_touch_ft5406.c')
	SOURCES     += Glob('touch/ft5406/hpm_ft5406.c')
	CPPPATH     += ['touch/ft5406']
	CPPDEFINES += ['CONFIG_TOUCH_FT5406=1']

if GetDepend(['BSP_USING_USB_DEVICE']):
	SOURCES     += Glob('usb/hpm_usb_device.c')
	CPPPATH     += ['usb/device']

if GetDepend(['BSP_USING_USB_HOST']):
	SOURCES     += Glob('usb/host/hpm_usb_host.c')
	CPPPATH     += ['usb/host']
	CPPDEFINES += ['USB_HOST_MCU_CORE=HPM_CORE0']

if GetDepend(['BSP_USING_ETH0']):
	if GetDepend(['BSP_USING_ENET_PHY_DP83867']):
		SOURCES     += Glob('enet_phy/dp83867/hpm_dp83867.c')
		CPPPATH     += ['enet_phy/dp83867']
		CPPPATH     += ['enet_phy']
		CPPDEFINES += ['__USE_DP83867=1']

if GetDepend(['BSP_USING_ETH1']):
	if GetDepend(['BSP_USING_ENET_PHY_DP83848']):
		SOURCES     += Glob('enet_phy/dp83848/hpm_dp83848.c')
		CPPPATH     += ['enet_phy/dp83848']
		CPPPATH     += ['enet_phy']
		CPPDEFINES += ['__USE_DP83848=1']

if GetDepend(['BSP_USING_ETH0']):
	if GetDepend(['BSP_USING_ENET_PHY_RTL8211']):
		SOURCES     += Glob('enet_phy/rtl8211/rtl8211.c')
		CPPPATH     += ['enet_phy/rtl8211']
		CPPPATH     += ['enet_phy']
		CPPDEFINES += ['__USE_RTL8211=1']
	if GetDepend(['BSP_USING_ENET_PHY_RTL8201']):
		SOURCES     += Glob('enet_phy/rtl8201/hpm_rtl8201.c')
		CPPPATH     += ['enet_phy/rtl8201']
		CPPPATH     += ['enet_phy']
		CPPDEFINES += ['__USE_RTL8201=1']

if GetDepend(['BSP_USING_ETH1']):
	if GetDepend(['BSP_USING_ENET_PHY_RTL8201']):
		SOURCES     += Glob('enet_phy/rtl8201/hpm_rtl8201.c')
		CPPPATH     += ['enet_phy/rtl8201']
		CPPPATH     += ['enet_phy']
		CPPDEFINES += ['__USE_RTL8201=1']
	if GetDepend(['BSP_USING_ENET_PHY_LAN8720']):
		SOURCES     += Glob('enet_phy/lan8720/hpm_lan8720.c')
		CPPPATH     += ['enet_phy/lan8720']
		CPPPATH     += ['enet_phy']
		CPPDEFINES += ['__USE_LAN8720=1']

if GetDepend(['BSP_USING_CAMERA']):
	CPPPATH     += ['camera']

if GetDepend(['BSP_USING_CAMERA_MT9M114']):
	SOURCES     += Glob('camera/mt9m114/hpm_mt9m114.c')
	SOURCES     += Glob('camera/mt9m114/hpm_camera_mt9m114.c')
	CPPPATH     += ['camera/mt9m114']
	CPPDEFINES += ['CONFIG_CAMERA_MT9M114=1']

if GetDepend(['BSP_USING_CAMERA_OV5640']):
	SOURCES     += Glob('camera/ov5640/hpm_camera_ov5640.c')
	SOURCES     += Glob('camera/ov5640/hpm_ov5640.c')
	CPPPATH     += ['camera/ov5640']
	CPPDEFINES += ['CONFIG_CAMERA_OV5640=1']

if GetDepend(['BSP_USING_CAMERA_OV7725']):
	SOURCES     += Glob('camera/ov7725/hpm_camera_ov7725.c')
	SOURCES     += Glob('camera/ov7725/hpm_ov7725.c')
	CPPPATH     += ['camera/ov7725']
	CPPDEFINES += ['CONFIG_CAMERA_OV7725=1']

if GetDepend(['BSP_USING_PANEL']):
	SOURCES     += Glob('panel/hpm_panel.c')
	CPPPATH     += ['panel']
	CPPDEFINES += ['CONFIG_HPM_PANEL']

if GetDepend(['BSP_USEING_PANEL_RGB_TM070RDH13']):
	SOURCES     += Glob('panel/panels/tm070rdh13.c')
	CPPPATH     += ['panel/panels']
	CPPDEFINES += ['PANEL_SIZE_WIDTH=800']
	CPPDEFINES += ['PANEL_SIZE_HEIGHT=480']
	CPPDEFINES += ['CONFIG_PANEL_RGB_TM070RDH13=1']

if GetDepend(['BSP_USEING_PANEL_MIPI_MC10128007_31B']):
	SOURCES     += Glob('panel/panels/mc10128007_31b.c')
	CPPPATH     += ['panel/panels']
	CPPDEFINES += ['PANEL_SIZE_WIDTH=800']
	CPPDEFINES += ['PANEL_SIZE_HEIGHT=1280']
	CPPDEFINES += ['CONFIG_PANEL_MIPI_MC10128007_31B=1']

if GetDepend(['BSP_USEING_PANEL_LVDS_TM103XDGP01']):
	SOURCES     += Glob('panel/panels/tm103xdgp01.c')
	CPPPATH     += ['panel/panels']
	CPPDEFINES += ['PANEL_SIZE_WIDTH=1920']
	CPPDEFINES += ['PANEL_SIZE_HEIGHT=720']
	CPPDEFINES += ['CONFIG_PANEL_LVDS_TM103XDGP01=1']

if GetDepend(['BSP_USEING_PANEL_LVDS_CC10128007']):
	SOURCES     += Glob('panel/panels/cc10128007.c')
	CPPPATH     += ['panel/panels']
	CPPDEFINES += ['PANEL_SIZE_WIDTH=800']
	CPPDEFINES += ['PANEL_SIZE_HEIGHT=1280']
	CPPDEFINES += ['CONFIG_PANEL_LVDS_CC10128007=1']

#---------------------------------------------------------------------------------
# Feature clip configuration, optional
#---------------------------------------------------------------------------------

#---------------------------------------------------------------------------------
# Compiler platform configuration, optional
#---------------------------------------------------------------------------------

#---------------------------------------------------------------------------------
# System variables
#---------------------------------------------------------------------------------
objs   = []
root   = GetCurrentDir()

#---------------------------------------------------------------------------------
# Sub target
#---------------------------------------------------------------------------------
list = os.listdir(root)
if GetDepend(DEPENDS):
    for d in list:
        path = os.path.join(root, d)
        if os.path.isfile(os.path.join(path, 'SConscript')):
            objs = objs + SConscript(os.path.join(d, 'SConscript'))

#---------------------------------------------------------------------------------
# Main target
#---------------------------------------------------------------------------------
objs += DefineGroup(name = PKGNAME, src = SOURCES, depend = DEPENDS, CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)

Return("objs")
#---------------------------------------------------------------------------------
# End
#---------------------------------------------------------------------------------
